package LeetCode;

public class LC_045_JumpGameII {
    public static void main(String[] args) {

    }

    class Solution {
        public int jump(int[] nums) {
            if (nums == null || nums.length == 0) {
                return -1;
            }
            int cur = 0;
            int last = 0;
            int step = 0;
            for (int i = 0; i < nums.length; i++) {
                if (i > last) {
                    step++;
                    last = cur;
                }
                cur = Math.max(cur, nums[i] + i);
            }
            return cur < nums.length - 1 ? -1 : step;
        }
    }

}
